import { createI18n } from "vue-i18n";
import en from "./en";
import { LocaleEnum } from "@/types";
// import vi from "./vi";
// import es from "./es";
// import zhCn from "./zhCn";
// import pt from "./pt";
import bn from "./bn";
//import { LanguageList } from "@/constant/language.ts";

const messages = {
  en,
  // zhCn,
  bn,
};
// const data = localStorage.getItem("userStore");
// const languageEnum = data
//   ? JSON.parse(data)?.userConfig?.profile?.language || LanguageEnum.LANGUAGE_PT
//   : ""; // 这是获取浏览器的语言
const language = (navigator.language || LocaleEnum.EN).toLocaleLowerCase(); // 这是获取浏览器的语言
console.log("@@@@@@@@@@@@@@language", language) //zh-cn ; bn ; en
//locale: LanguageList.find(item => item.value === languageEnum)?.locale || LocaleEnum.PORTUGUESE,
const selectedLanguage = localStorage.getItem("selectLanguage") || language;
const i18n = createI18n({
  locale:
    selectedLanguage == "bn"
      ? LocaleEnum.BN
      : LocaleEnum.EN,
  fallbackLocale: LocaleEnum.EN, // 设置备用语言
  messages,
  legacy: false,
  globalInjection: true,
});

export function setI18nLanguage(currLangue: string): void {
  localStorage.setItem("selectLanguage", currLangue);
  i18n.global.locale.value =
    currLangue == "en" ? LocaleEnum.EN : LocaleEnum.BN;
}

export default i18n;
/*  */
